using UnityEngine;

public class OnChargeArrow : OnChargeExplosionAdhesive
{
	[SerializeField]
	private bool hideForWeakDevice;

	public override void Awake()
	{
		base.Awake();
		base.gameObject.name = base.gameObject.name.Replace("(Clone)", string.Empty);
		if (hideForWeakDevice && !base.isMine && Device.indexWeakDevice != 0)
		{
			base.gameObject.GetComponentInChildren<MeshRenderer>().enabled = false;
		}
	}

	public override void OnCollisionEnter(Collision collision)
	{
		if (!base.isMine)
		{
			return;
		}
		Mortal componentInParent = collision.gameObject.GetComponentInParent<Mortal>();
		if ((bool)componentInParent)
		{
			if (TDMController.isTeamGameType && base.photonView.isMine)
			{
				if (componentInParent is EntityBehavior)
				{
					EntityBehavior entityBehavior = componentInParent as EntityBehavior;
					PlayerBehavior playerBehavior = entityBehavior.getMainHuman() as PlayerBehavior;
					PlayerBehavior playerBehavior2 = GameController.instance.FindPlayer(entityBehavior.photonView.ownerId);
					if ((entityBehavior.getMainHuman() != null && playerBehavior != null && playerBehavior.localTeam == TDMController.myTeam && !entityBehavior.isMine) || (entityBehavior.privateCar && playerBehavior2 != null && playerBehavior2.localTeam == TDMController.myTeam))
					{
						return;
					}
				}
				else if (componentInParent is PlayerBehavior)
				{
					PlayerBehavior playerBehavior3 = componentInParent as PlayerBehavior;
					if (playerBehavior3.localTeam == TDMController.myTeam && !playerBehavior3.isMine)
					{
						return;
					}
				}
			}
			bool isHeadshot = false;
			if (collision.collider.tag == "ShootHead")
			{
				componentInParent.ShowCriticalDamage();
				damage *= 1.5f;
				isHeadshot = true;
			}
			SendDamage(componentInParent, damage, Vector3.down * 100f, isHeadshot);
		}
		GameObject gameObject = null;
		gameObject = ((!componentInParent) ? collision.gameObject : componentInParent.gameObject);
		Transform[] componentsInChildren = gameObject.GetComponentsInChildren<Transform>();
		Transform transform = componentsInChildren[0];
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if (Vector3.Distance(componentsInChildren[i].position, base.transform.position) < Vector3.Distance(transform.position, base.transform.position))
			{
				transform = componentsInChildren[i];
			}
		}
		if ((bool)componentInParent)
		{
			if (!settings.offlineMode)
			{
				componentInParent.photonView.RPC("AttachArrow", PhotonTargets.All, transform.name, base.gameObject.transform.localPosition, base.gameObject.transform.localRotation, base.gameObject.name);
			}
			else
			{
				componentInParent.AttachArrow(transform.name, base.gameObject.transform.localPosition, base.gameObject.transform.localRotation, base.gameObject.name);
			}
			Destroy();
		}
		else
		{
			AttachToParent(base.ID, transform.name, base.gameObject.transform.localPosition, base.gameObject.transform.localRotation);
			RemoveAllComponnents();
			Invoke("Destroy", lifeTime);
		}
	}

	public override void BlowUp()
	{
	}

	public override void OnDisable()
	{
		if (settings.offlineMode)
		{
			Object.Destroy(base.gameObject);
		}
	}

	public void Destroy()
	{
		PhotonNetwork.Destroy(base.gameObject);
	}

	protected override void OnDestroy()
	{
	}

	public void RemoveAllComponnents()
	{
		rigid = GetComponent<Rigidbody>();
		rigid.useGravity = false;
		rigid.isKinematic = true;
		Object.Destroy(GetComponent<Collider>());
		Object.Destroy(GetComponent<TrailRenderer>());
		Object.Destroy(GetComponent<AudioSource>());
	}
}
